<template>
  <view class="doctor-container">
    <!-- 医生基本信息 -->
    <view class="doctor-header">
      <view class="avatar-section">
        <image class="doctor-avatar" :src="doctorInfo.imgUrl" mode="aspectFill"></image>
        <view class="online-status"></view>
      </view>
      <view class="basic-info">
        <view class="name-title">
          <text class="doctor-name">{{doctorInfo.name}}</text>
          <view class="title-tag">{{doctorInfo.title}}</view>
        </view>
        <view class="hospital-info">
          <text>{{doctorInfo.department}}</text>
          <text class="separator">|</text>
          <text>{{doctorInfo.hospital}}</text>
        </view>
        <view class="tags">
          <text class="tag">专业认证</text>
          <text class="tag">及时回复</text>
          <text class="tag">优质服务</text>
        </view>
      </view>
    </view>

    <!-- 医生详细信息 -->
    <view class="detail-section">
      <view class="section-title">
        <text class="title">擅长领域</text>
      </view>
      <view class="content-box">
        <text class="content">{{doctorxx.expertise}}</text>
      </view>

      <view class="section-title">
        <text class="title">执业经历</text>
      </view>
      <view class="content-box">
        <text class="content">
         {{doctorxx.workexperience}}
        </text>
      </view>

      <view class="section-title">
        <text class="title">出诊时间</text>
      </view>
      <view class="content-box">
        <text class="content">{{doctorxx.clinictime}}</text>
      </view>

      <!-- 评价区域 -->
      <view class="section-title">
        <text class="title">评价</text>
      </view>
      <view class="reviews-section">
        <view class="review-stats">
          <text class="rating">4.5</text>
          <!-- <text class="total-reviews">共368条评价</text> -->
        </view>
        <view class="review-tags">
          <text class="tag">医术精湛 299</text>
          <text class="tag">态度好 256</text>
          <text class="tag">解释详细 233</text>
          <text class="tag">及时回复 189</text>
        </view>
      </view>
    </view>

    <!-- 底部操作栏 -->
    <view class="bottom-bar">
      <view class="price-info">
        <text class="price">¥{{doctorInfo.price}}</text>
        <text class="unit">/次</text>
      </view>
      <view class="action-buttons">
        <button class="consult-btn" @tap="startConsultation">立即咨询</button>
      </view>
    </view>
  </view>
</template>

<script>
import { doctorApi } from '@/api/doctor'
export default {
  data() {
    return {
      doctorInfo: {},
	  doctorxx:{},
	  id:0,
	  healthData: {
	    height: 170,
	    weight: 65,
	    bmi: 22.5,
	    bloodPressure: '120/80'
	  }
    }
  },

  onLoad(options) {
    if (options.doctorInfo) {
      try {
        this.doctorInfo = JSON.parse(decodeURIComponent(options.doctorInfo))
		this.id=this.doctorInfo.id
      } catch (error) {
        console.error('解析医生信息失败:', error)
        uni.showToast({
          title: '获取医生信息失败',
          icon: 'none'
        })
      }
    }
    this.getDoctorInfoo(this.id)
  },
  methods: {
    goBack() {
      uni.navigateBack()
    },
	startConsultation() {
	  // 使用reLaunch跳转并传递医生信息
	  uni.reLaunch({
	    url: `/pages/doctorAI/ai?doctorInfo=${encodeURIComponent(JSON.stringify(this.doctorInfo))}`,
	    success: function() {
	      console.log('跳转成功');
	    },
	    fail: function(err) {
	      console.error('跳转失败:', err);
	      // 如果仍然失败，尝试不同的路径
	      uni.reLaunch({
	        url: '/pages/index/index',
	        success: function() {
	          console.log('回到首页成功');
	        }
	      });
	    }
	  });
	},
	async getDoctorInfoo(id){
		try{
			const res=await doctorApi.getDoctorInfo(id)
			this.doctorxx=res.data
			console.log(this.doctorxx)
		}catch(error){
			console.error(error)
			uni.showToast({
				title:'加载失败',
				icon: 'none'
			})
		}
	}
  }
}
</script>

<style lang="scss">
.doctor-container {
  min-height: 100vh;
  background: #f7f8fa;
  padding-bottom: 120rpx;

  .doctor-header {
    margin-top: 0;
    background: #ffffff;
    padding: 40rpx 30rpx;
    display: flex;
    align-items: center;

    .avatar-section {
      position: relative;
      margin-right: 30rpx;

      .doctor-avatar {
        width: 160rpx;
        height: 160rpx;
        border-radius: 80rpx;
        background: #f0f0f0;
      }

      .online-status {
        position: absolute;
        right: 4rpx;
        bottom: 4rpx;
        width: 20rpx;
        height: 20rpx;
        border-radius: 50%;
        background: #00C190;
        border: 2rpx solid #fff;
      }
    }

    .basic-info {
      flex: 1;

      .name-title {
        display: flex;
        align-items: center;
        margin-bottom: 16rpx;

        .doctor-name {
          font-size: 36rpx;
          color: #333;
          font-weight: 600;
          margin-right: 20rpx;
        }

        .title-tag {
          font-size: 24rpx;
          color: #00C190;
          background: rgba(0, 193, 144, 0.1);
          padding: 4rpx 16rpx;
          border-radius: 4rpx;
        }
      }

      .hospital-info {
        font-size: 28rpx;
        color: #666;
        margin-bottom: 16rpx;

        .separator {
          margin: 0 16rpx;
          color: #ddd;
        }
      }

      .tags {
        display: flex;
        flex-wrap: wrap;

        .tag {
          font-size: 24rpx;
          color: #666;
          background: #f7f8fa;
          padding: 4rpx 16rpx;
          border-radius: 4rpx;
          margin-right: 16rpx;
          margin-bottom: 8rpx;
        }
      }
    }
  }

  .detail-section {
    margin-top: 20rpx;
    background: #ffffff;
    padding: 0 30rpx;

    .section-title {
      padding: 30rpx 0 20rpx;
      border-bottom: 2rpx solid #f5f5f5;

      .title {
        font-size: 32rpx;
        color: #333;
        font-weight: 600;
      }
    }

    .content-box {
      padding: 20rpx 0 30rpx;

      .content {
        font-size: 28rpx;
        color: #666;
        line-height: 1.6;
        white-space: pre-line;
      }
    }

    .reviews-section {
      padding: 20rpx 0;

      .review-stats {
        display: flex;
        align-items: baseline;
        margin-bottom: 20rpx;

        .rating {
          font-size: 48rpx;
          color: #333;
          font-weight: bold;
          margin-right: 20rpx;
        }

        .total-reviews {
          font-size: 24rpx;
          color: #999;
        }
      }

      .review-tags {
        display: flex;
        flex-wrap: wrap;
        gap: 20rpx;

        .tag {
          font-size: 24rpx;
          color: #666;
          background: #f5f7fa;
          padding: 8rpx 20rpx;
          border-radius: 20rpx;
        }
      }
    }
  }

  .bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100rpx;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30rpx;
    box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);

    .price-info {
      .price {
        font-size: 40rpx;
        color: #ff6b6b;
        font-weight: bold;
      }

      .unit {
        font-size: 24rpx;
        color: #999;
      }
    }

    .action-buttons {
      .consult-btn {
        background: #00C190;
        color: #ffffff;
        font-size: 32rpx;
        padding: 0 60rpx;
        height: 80rpx;
        line-height: 80rpx;
        border-radius: 40rpx;
        border: none;

        &:active {
          opacity: 0.9;
        }
      }
    }
  }
}
</style> 